package com.swpu.service_remind.controller;


import com.swpu.commonutils.JwtUtils;
import com.swpu.commonutils.R;
import com.swpu.commonutils.ResultEncryption;
import com.swpu.service_remind.entity.CheckupRemind;
import com.swpu.service_remind.entity.DrinkRemind;
import com.swpu.service_remind.service.CheckupRemindService;
import com.swpu.service_user.aop.Decrypt;
import com.swpu.service_user.aop.Encrypt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chaichai
 * @since 2024-03-22
 */
@RestController
@RequestMapping("/service_remind/checkup-remind")
public class CheckupRemindController {
        @Autowired
    private CheckupRemindService checkupRemindService;
    @PostMapping("/saveCheckupRemindSetting")
    @Decrypt
    @Encrypt
    public R saveUserDrinkRemindSetting(@RequestBody ResultEncryption resultEncryption,  CheckupRemind checkupRemind, HttpServletRequest request){
        String openid = JwtUtils.getOpenidByJwtToken(request);
        if (openid.isEmpty()){
            return R.error().message("当前用户未登录");
        }
        checkupRemindService.saveCheckupRemindSetting(openid,checkupRemind);
        return R.ok();
    }
    @GetMapping("/getCheckupRemindSetting")
    public R getDrinkRemindSetting(HttpServletRequest request){
        String openid = JwtUtils.getOpenidByJwtToken(request);
        if (openid.isEmpty()){
            return R.error().message("当前用户未登录");
        }
        CheckupRemind checkupRemind = checkupRemindService.getCheckupRemindSetting(openid);
        return R.ok().data("checkupRemind",checkupRemind);
    }
 }

